<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>选择题库管理</title>

    <style>

    </style>

</head>
<body>
<h2>选择题库列表</h2>
欢迎${pageContext.request.session.getAttribute("userInfo").name}使用现在考试系统&nbsp;&nbsp;<a href="javascript:logOut({project_name:'${ctx}'});">注销</a>
<br/>
<a href="e_selection_add_update.jsp" target="_blank">添加模块+</a>&nbsp;&nbsp;

<br/>
<div id="selection_list">

</div>
<a href="javascript:void(0);" id="turnUp">上页</a>
<a href="javascript:void(0);" id="turnDown">下页</a>
当前页码：<input type="text" value="1" id="cur_page"/>
每页记录数：<input type="text" value="10" id="page_size"/>
<input type="button" value="跳转" id="turn_page">
<span id="page_span"></span>



<script src="${ctx}/common/jquery/jquery-3.5.0.js"></script>
<script src="${ctx}/examination/common_module/js/sys_user.js"></script>
<script>
    /**
     * 1)       limit分页公式
     （1）limit分页公式：curPage是当前第几页；pageSize是一页多少条记录
     limit (curPage-1)*pageSize,pageSize
     （2）用的地方：sql语句中
     select * from student limit(curPage-1)*pageSize,pageSize;

     2)       总页数公式
     （1）总页数公式：totalRecord是总记录数；pageSize是一页分多少条记录
     int totalPageNum = (totalRecord +pageSize - 1) / pageSize;
     （2）用的地方：前台UI分页插件显示分页码
     （3）查询总条数：totalRecord是总记录数
     SELECT COUNT(*) FROM tablename
     */
    /**
     * 编辑
     * @param id
     */
    function  edit_selection(id) {
        alert("edit:"+id);
    }
    /**
     * 删除
     * @param id
     */
    function  del_selection(id) {
        alert("del:"+id);
    }
    $(document).ready(function(){
        $("#turnUp").click(function(){
            var curPage = Number($("#cur_page").val()) - 1;//当前页码
            var pageInfo = {
                curPage:curPage
            }
            turnPage(pageInfo);
            $("#cur_page").val(curPage);
        });
        $("#turnDown").click(function(){
            var curPage = Number($("#cur_page").val()) + 1;//当前页码
            var pageInfo = {
                curPage:curPage
            }
            turnPage(pageInfo);
            $("#cur_page").val(curPage);
        });
        $("#turn_page").click(function(){
            var curPage = $("#cur_page").val();//当前页码
            var pageSize = $("#page_size").val();//每页记录数
            var pageInfo = {
                curPage:curPage,
                pageSize:pageSize
            }
            turnPage(pageInfo);
        });


        //方法跳转
        function turnPage(pageInfo){
            var defaultPageInfo={
                curPage:1,
                pageSize:10
            };
            $.extend(defaultPageInfo,pageInfo);
            $.ajax({
                url:"${ctx}/SelectionAdmin?methodName=getSelectionListByPage",
                data:defaultPageInfo,
                type:"post",
                success:function(result){
                    // $("#div1").html(result);
                    // alert("ajax回调成功"+result);
                    // console.log(result);
                    var state = result.state;
                    if(state == '200'){
                        var msg = result.msg;
                        var pageInfo = result.data;
                        var list = pageInfo.objList;
                        var dataTab = '';
                        dataTab += '<table border="1">';
                        dataTab += '<tr>';
                        dataTab += '<td>类型</td>';
                        dataTab += '<td>内容</td>';
                        dataTab += '<td>选项信息</td>';
                        dataTab += '<td>正确答案</td>';
                        dataTab += '<td>答案信息</td>';
                        dataTab += '<td>操作</td>';
                        dataTab += '</tr>';
                        for (var i = 0; i < list.length; i++) {
                            var selection = list[i];
                            dataTab += '<tr>';
                            dataTab += '<td>'+selection.type+'</td>';
                            dataTab += '<td>'+selection.content+'</td>';
                            dataTab += '<td>'+selection.choiceInfo+'</td>';
                            dataTab += '<td>'+selection.answer+'</td>';
                            dataTab += '<td>'+selection.answerInfo+'</td>';
                            dataTab += '<td><a href="javascript:edit_selection('+selection.id+')">编辑</a>&nbsp;<a href="javascript:del_selection('+selection.id+')">删除</a></td>';
                            dataTab += '</tr>';
                            var obj = list[i];
                        }
                        dataTab += '</table>';
                        $("#selection_list").html(dataTab);
                        //分页信息
                        var curPage = pageInfo.curPage;
                        var pageSize = pageInfo.pageSize;
                        var countNum = pageInfo.countNum;
                        var totalPageNum = pageInfo.totalPageNum;
                        var pageStr = "countNum:"+countNum+" curPage："+curPage+" pageSize:"+pageSize+" totalPageNum:"+totalPageNum;
                        $("#page_span").html(pageStr);
                    }
                }
            });
        }
        turnPage();
    });
</script>
</body>
</html>
